<template>
	<view>
		<navbar title="添加交易" :isbg="false" :autoBack="true" :opacity='1'>
			
		</navbar>
		<view class="con">
			<view class="box">
				<view class="box__item">
					<view class="box__item__label">
						成交日期:
					</view>
					<view class="box__item__inp" @click="show=true">
						{{time?time:'请选择成交日期'}}
					</view>
				</view>
				<view class="box__item">
					<view class="box__item__label">
						成交金额(元):
					</view>
					<input type="number" class="box__item__inp" v-model="form.price" placeholder="请输入成交金额" />
				</view>
				<view class="" style="padding:26rpx 20rpx 0 0;">
					<u--textarea v-model="form.remark" height='242rpx' border='none'
						placeholder="请输入备注信息"></u--textarea>
					<u-button text="提交" @click="submit" :loading="btnloading" color="#2A51FA" :customStyle="{
						height:'95rpx',
						width:'638rpx',
						margin:0,
						fontSize:'30rpx',
						borderRadius:'20rpx'
					}"></u-button>
				</view>
			</view>
		</view>
		<u-datetime-picker :show="show" v-model="value1" @cancel="show=false" :closeOnClickOverlay='true' @confirm="confirm" mode="date"></u-datetime-picker>
	</view>
</template>

<script>
	import datagl from '@/api/_datagl.js'
	export default {
		data() {
			return {
				show: false,
				value1: Number(new Date()),
				form: {
					customer_id: '',
					remark: '',
					price:''
				},
				btnloading:false
			};
		},
		methods: {
			confirm(e){
				this.time=uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
				this.show=false
			},
			async submit() {
				let {
					price,
					remark
					} = this.form
				
				if (!price) {
					uni.$u.toast('请输入成交金额')
					return
				}
				if (!remark) {
					uni.$u.toast('内容不能为空')
					return
				}
				this.btnloading=true
				let res = await datagl.createTrade(this.form)
				if (res.data.code == 1) {
					uni.$u.toast('添加成功')
					this.btnloading=false
					const pages = getCurrentPages(); // 获取页面栈
					const beforePage = pages[pages.length - 2]; // 上一个页面
					beforePage.$vm.getlist(); // 调用上一个页面的方法
					uni.navigateBack()
				}
			}
		},
		onLoad(o) {
			this.form.customer_id = o.id
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F0F3F7;
	}

	.con {
		padding: 30rpx;
	}

	.box {
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 18rpx 4rpx 56rpx 30rpx;

		&__title {
			display: flex;
			align-items: center;
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #6D6D6D;
			line-height: 28rpx;
			margin-bottom: 28rpx;
			margin-top: 36rpx;

			&__line {
				width: 6rpx;
				height: 27rpx;
				background: #2DA1E0;
				border-radius: 3rpx 3rpx 3rpx 3rpx;
				margin-right: 10rpx;
			}
		}

		&__item {
			height: 100rpx;
			border-bottom: 2rpx solid #F9F9F9;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 25rpx;

			&__label {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #6D6D6D;
				line-height: 38rpx;
			}

			&__inp {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #020202;
				line-height: 38rpx;
				text-align: right;
				flex: 1;
			}
		}

		&__addr {
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #010101;
			line-height: 38rpx;
			padding-bottom: 24rpx;
			border-bottom: 2rpx solid #F9F9F9;
		}
	}

	::v-deep.u-textarea {
		background-color: #F8F8F8 !important;
		border-radius: 20rpx !important;
		padding: 20rpx !important;
	}

	.btn {
		width: 638rpx;
		height: 95rpx;
		background: #2A51FA;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang-SC, PingFang-SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 48rpx;
		margin-top: 39rpx;
	}
</style>